package com.itheima.web;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;

import com.tencentcloudapi.captcha.v20190722.CaptchaClient;
import com.tencentcloudapi.captcha.v20190722.models.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class DescribeCaptchaResultController {
    @PostMapping("/validate")
    public String validate(@RequestBody Map map) {
        String tikect = (String)map.get("tikect");
        String randstr = (String)map.get("randstr");
        try{

            Credential cred = new Credential("AKIDbOyKPHIRj9JVB1o7PSGozrHD7nERbYR6",
                    "a0CeroW0HJ8yaz83kX6VdYEigFenhMvF");

            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("captcha.tencentcloudapi.com");

            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);

            CaptchaClient client = new CaptchaClient(cred, "", clientProfile);

            DescribeCaptchaResultRequest req = new DescribeCaptchaResultRequest();
            req.setCaptchaType(9L);
            req.setUserIp("127.0.0.1");
            req.setRandstr(randstr);
            req.setCaptchaAppId(2026544900L);
            req.setAppSecretKey("0Le3LYLI9H4sG_wFwi-eCiw**");
            req.setTicket(tikect);

            DescribeCaptchaResultResponse resp = client.DescribeCaptchaResult(req);

            System.out.println(DescribeCaptchaResultResponse.toJsonString(resp));
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
        return "ok";

    }

}
